***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "Main_Table2"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE 2 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M mk com_property" // ptySR_F_N" //  com_property"
global ctrl_plus	"mean_votation lcrSR_F_N"
global fe			"charact_agglo"
global fe_iv		"I_charact_agglo_*"
global cluster		"charact_agglo"

// Column 1

reghdfe oui endog_mk /// 
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	 
estimates store OLS
	
// Column 2

reghdfe oui endog_mk /// 
	$ctrl_plus /// 
	$ctrl_base ///	
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store OLS_ctrl
		
// Column 3
		
reghdfe oui instr_dev_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing
estimates store RF_dev_ctrl

// Column 4

reghdfe endog_mk instr_dev_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store FS_dev_ctrl
test instr_dev_mk
estadd scalar F_fs=r(F)
		
// Column 5

reghdfe oui $ctrl_plus $ctrl_base (endog_mk = instr_dev_mk) ///
	if sample_hq00dstr==1, ///
	cluster($cluster) absorb($fe) old keepsing
estimates store TSLS_dev_ctrl

// Get sample

qui: reghdfe oui endog_mk /// 
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
		
keep if e(sample)

// Column 1

acreg oui  $ctrl_base  ///
	endog_mk, ///
	spatial latitude(latitude) longitude(longitude) id(commune) time(year) lag(100000) dist(15) lagdist(0) pfe1(charact_agglo) 
estimates store OLS_S

// Column 2

acreg oui  $ctrl_base $ctrl_plus  ///
	endog_mk , ///
	spatial latitude(latitude) longitude(longitude) id(commune) time(year) lag(100000) dist(15) lagdist(0) pfe1(charact_agglo) 
estimates store OLS_ctrl_S
		
// Column 3

acreg oui  $ctrl_base $ctrl_plus  ///
	instr_dev_mk, ///
	spatial latitude(latitude) longitude(longitude) id(commune) time(year) lag(100000) dist(15) lagdist(0) pfe1(charact_agglo) 
estimates store RF_dev_ctrl_S

// Column 4

acreg endog_mk  $ctrl_base $ctrl_plus  ///
	instr_dev_mk, ///
	spatial latitude(latitude) longitude(longitude) id(commune) time(year) lag(100000) dist(15) lagdist(0) pfe1(charact_agglo) 
estimates store FS_dev_ctrl_S
test instr_dev_mk
estadd scalar F_fs=r(chi2)
		
// Column 5

acreg oui  $ctrl_base $ctrl_plus  ///
	(endog_mk = instr_dev_mk), ///
	spatial latitude(latitude) longitude(longitude) id(commune) time(year) lag(100000) dist(15) lagdist(0) pfe1(charact_agglo) 
estimates store TSLS_dev_ctrl_S
	
// Labels

la var endog_mk 		"Crime News Exposure ($ \mathtt{CNE} $)"
la var instr_dev_mk 	"HQ Crime Prop. Diff. Deviation ($ \mathtt{\Delta HQC} $)"
la var lcrSR_F_N 		"Local Crime Propensity Differential ($ \mathtt{CPD} $)"
la var mean_votation 	"Past Vote Outcomes"

// Table
	
estout OLS OLS_ctrl RF_dev_ctrl FS_dev_ctrl TSLS_dev_ctrl ///
	using "$Results\\$program.tex", replace style(tex) type label	///
	cells(b(fmt(%9.3f)) se(star par fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(endog_mk) /// 
	title(News and voting: Main results) ///	
	prehead("\begin{table}[!h]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{small}" ///
	"\caption{@title\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///	
	"\\" ///
	"Specification		&							&			&\multicolumn{1}{c}{Reduced}	&\multicolumn{1}{c}{2SLS}	&\multicolumn{1}{c}{2SLS} \\" ///
	"					&\multicolumn{2}{c}{OLS} 				&\multicolumn{1}{c}{Form}		&\multicolumn{1}{c}{1st Stage}	&\multicolumn{1}{c}{2nd Stage} \\" ///
	"					\cmidrule(lr){2-3} 						\cmidrule(lr){4-4} 				\cmidrule(lr){5-6}	" ///
	"Dependent Variable &\multicolumn{1}{c}{\%Yes}	&\multicolumn{1}{c}{\%Yes} 	&\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes} \\" ///
	"					\cmidrule(lr){2-3} 						\cmidrule(lr){4-4} 				\cmidrule(lr){5-6}	" ///
	"					&\multicolumn{1}{c}{(1)} 	&\multicolumn{1}{c}{(2)}  	&\multicolumn{1}{c}{(3)} &\multicolumn{1}{c}{(4)}  	&\multicolumn{1}{c}{(5)} \\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("") ///
	postfoot("")

la var endog_mk 		" "
estout OLS_S OLS_ctrl_S RF_dev_ctrl_S FS_dev_ctrl_S TSLS_dev_ctrl_S ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(se(star par([ ]) fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(endog_mk) /// 
	prehead("") ///
	posthead("") ///
	prefoot("") ///
	postfoot("")

estout OLS OLS_ctrl RF_dev_ctrl FS_dev_ctrl TSLS_dev_ctrl ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(b(fmt(%9.3f)) se(star par fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(mean_votation) /// 
	prehead("") ///
	posthead("\\") ///
	prefoot("") ///
	postfoot("")

la var mean_votation 		" "
estout OLS_S OLS_ctrl_S RF_dev_ctrl_S FS_dev_ctrl_S TSLS_dev_ctrl_S ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(se(star par([ ]) fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(mean_votation) /// 
	prehead("") ///
	posthead("") ///
	prefoot("") ///
	postfoot("")

estout OLS OLS_ctrl RF_dev_ctrl FS_dev_ctrl TSLS_dev_ctrl ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(b(fmt(%9.3f)) se(star par fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(lcrSR_F_N) /// 
	prehead("") ///
	posthead("\\") ///
	prefoot("") ///
	postfoot("")

la var lcrSR_F_N 		" "
estout OLS_S OLS_ctrl_S RF_dev_ctrl_S FS_dev_ctrl_S TSLS_dev_ctrl_S ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(se(star par([ ]) fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(lcrSR_F_N) /// 
	prehead("") ///
	posthead("") ///
	prefoot("") ///
	postfoot("")

estout OLS OLS_ctrl RF_dev_ctrl FS_dev_ctrl TSLS_dev_ctrl ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(b(fmt(%9.3f)) se(star par fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(instr_dev_mk) /// 
	prehead("") ///
	posthead("\\") ///
	prefoot("") ///
	postfoot("")

la var instr_dev_mk 		" "
estout OLS_S OLS_ctrl_S RF_dev_ctrl_S FS_dev_ctrl_S TSLS_dev_ctrl_S ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(se(star par([ ]) fmt(%9.3f)))  ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(instr_dev_mk) /// 
	prehead("") ///
	posthead("") ///
	prefoot("") ///
	postfoot("")

estout OLS OLS_ctrl RF_dev_ctrl FS_dev_ctrl TSLS_dev_ctrl ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(b(fmt(%9.3f)) se(star par fmt(%9.3f)))  ///
	stats(N r2_a F_fs, lab("Observations" "Adjusted $ R^2 $" "First-stage F-statistic (agglo cluster)") fmt(0 3 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	drop(*) /// 
	prehead("") ///
	posthead("") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("")

estout OLS_S OLS_ctrl_S RF_dev_ctrl_S FS_dev_ctrl_S TSLS_dev_ctrl_S ///
	using "$Results\\$program.tex", append style(tex) type label	///
	cells(se(star par([ ]) fmt(%9.3f)))  ///
	stats(F_fs, lab("First-stage F-statistic (spatial cluster)") fmt(2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	drop(*) /// 
	prehead("") ///
	posthead("") ///
	prefoot("") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{small}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"The unit of observation is a municipality. " /// 
	"Standard errors clustered at agglomeration level in parentheses. " ///
	"Standard errors corrected for cross-sectional spatial correlation within 15km in brackets. " /// 
	"{$^c$} significant at 10\%; {$^b$} significant at 5\%; {$^a$} significant at 1\%. " ///
	"Columns (1) and (2) show the OLS estimates. Columns (3) to (5) present the estimates of our preferred specification, " /// 
	"the 2SLS estimation based on the $ \mathtt{\Delta HQC}_{m} $ instrument computed as the short-run Crime Propensity Differential in newspaper " ///
	"headquarter areas ($ \mathtt{HQC}_{m} $) in deviation from its long-run counterpart  ($ \mathtt{HQC}^{\mathtt{LR}}_{m} $). " ///
	"Municipality characteristics are included in all specifications: population size, share of German-speaking population, share of immigrants, net immigration, sectoral employment, average income, squared average income, elevation, ruggedness, share of active population, share of young population (15-35 population), share of Protestants, share of Muslims, property crimes, and total market shares of the eleven newspapers included in this analysis. " /// 
	"Agglomeration fixed effects are included in all specifications." ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
